/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 有点呆
 * Date: 2024-10-31
 * Time: 16:07
 */

import java.util.List;
import java.util.Scanner;
import java.util.ArrayList;

public class ShortJobFirst {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        System.out.println("短作业优先调度算法（sjf）开始：");
        System.out.println("请先输入作业的相关信息：（输入no代表结束）");

        List<Job> jobs = new ArrayList<>();

        List<Job> execJobs = new ArrayList<>();

        do {
            Job job = new Job();
            Job initJob = ShortJobFirstUtil.init(job);
            jobs.add(initJob);
            System.out.println("是否需要继续输入作业相关信息：（是输入yes，否输入no）");
        } while (scanner.nextLine().equalsIgnoreCase("yes"));
        System.out.println("---------------");

        //确认初始化成功
		for (Job job : jobs) {
			System.out.println(job.toString());
		}

        ShortJobFirstUtil.sleepJob(jobs);
        System.out.println("---------------");

        ShortJobFirstUtil.dispatchJob(jobs, execJobs);

        for (Job job : execJobs) {
			System.out.println(job.toString());
		}
		//作业信息根据服务时间递增排序
		ShortJobFirstUtil.sortByServerTime(jobs);
		//确认排序成功
		for (Job job : jobs) {
			System.out.println(job.toString());
		}

        ShortJobFirstUtil.turnRoundTime(execJobs);
        for (Job job : execJobs) {
            System.out.println(job.toString());
        }

        System.out.println("----------------");
        ShortJobFirstUtil.showTime(execJobs);
    }
}
